//
//  SingleViewController.m
//  UIPickerViewDemo
//
//  Created by Justsoso on 16/2/23.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "SingleViewController.h"

@interface SingleViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) NSArray *list;

@end

@implementation SingleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.list = @[@"王五",@"赵六",@"太君",@"小野君",@"小日本",@"王叔叔",@"背锅侠"];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)btnPressed:(id)sender
{
    int sel = [self.pickerView selectedRowInComponent:0];
    NSString *name = self.list[sel];
    
//    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"选择了谁?" message:name delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
//    [alert show];
    
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"选择了谁?" message:name preferredStyle:UIAlertControllerStyleAlert];
    
    [self presentViewController:alert animated:YES completion:nil];
    
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
    
    [alert addAction:sureAction];
}



// returns the number of 'columns' to display.
// 有几列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
// 第几行有几列
// returns the # of rows in each component..
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return self.list.count;
}




- (nullable NSString *)pickerView:(UIPickerView *)pickerView
                      titleForRow:(NSInteger)row
                     forComponent:(NSInteger)component
{
    return self.list[row];
}
- (void)pickerView:(UIPickerView *)pickerView
      didSelectRow:(NSInteger)row
       inComponent:(NSInteger)component
{
    self.infoLabel.text = self.list[row];
}


@end
